<!--
 * @Author: JunyaoPan
 * @Date: 2021-09-26 10:13:33
 * @LastEditors: JunyaoPan
 * @LastEditTime: 2021-10-15 18:39:01
 * @Description: 
-->
<template>
  <div>
    <!-- 头部 -->
    <Header></Header>
    <!-- 内容 -->
    <div class="content_detail" v-if="categoryId1">
      <div class="content_left" v-for="item in list.slice(0, 1)" :key="item.id">
        <div>{{ item.category.name }}</div>
      </div>
      <div class="content_right_detail">
        <!-- 标题 -->
        <div
          class="content_right_top"
          v-for="item in list.slice(0, 1)"
          :key="item.id"
        >
          <div class="content_right_title">{{ item.category.name }}</div>
          <div>
            当前位置 ·
            <span @click="toHome">首页 ·</span>
            {{ item.category.name }}
          </div>
        </div>
        <!-- 列表 -->
        <div class="content_right_center">
          <ul>
            <li
              v-for="item in list"
              :key="item.id"
              @click="toDetailList(item.id)"
            >
              <span style="float: left">{{ item.title }}</span>
              <span style="float: right">{{ item.publishTime | fmtDate }}</span>
            </li>
          </ul>
        </div>
      </div>
      <!-- 分页 -->
      <div class="content_right_bottom">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[8, 15, 30, 40]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :hide-on-single-page="true"
        >
        </el-pagination>
      </div>
    </div>
    <div class="content_content" v-if="id">
      <div class="content_left">
        <div>{{ categoryName }}</div>
      </div>
      <div class="content_right_content">
        <!-- 标题 -->
        <div class="content_right_top">
          <div class="content_right_title">{{ categoryName }}</div>
          <div>
            当前位置 ·
            <span @click="toHome">首页 ·</span>
            {{ categoryName }}
            · 正文
          </div>
        </div>
        <div>
          <div class="content_content_title">{{ title }}</div>
          <div v-html="content">
            {{ content }}
          </div>
        </div>
      </div>
    </div>

    <!-- 脚注 -->
    <Footer></Footer>
  </div>
</template>

<script>
import Header from "./components/Header.vue";
import Footer from "./components/Footer.vue";
import { get } from "../utils/request";
export default {
  data() {
    return {
      list: [],
      currentPage: 1,
      pageSize: 8,
      total: 0,
      // categoryId1: this.$route.query.categoryId,
      // id: this.$route.query.id,
      categoryId1: 0,
      id: 0,
      content: "",
      title: "",
      categoryName: "",
    };
  },
  created() {
    this.getList();
    this.getContent();
  },
  methods: {
    // 跳转到主页
    toHome() {
      this.$router.push({
        path: "/",
      });
    },
    // 页面资讯查询
    async getList() {
      this.categoryId1 = this.$route.query.categoryId;
      if (this.categoryId1) {
        let data = {
          page: this.currentPage,
          pageSize: this.pageSize,
          categoryId: this.$route.query.categoryId,
        };
        let res = await get("/index/article/pageQuery", data);
        this.list = res.data.list;
        this.total = res.data.total;
        console.log(res, "res1");
      }
      console.log(this.categoryId1);
    },
    async getContent() {
      this.id = this.$route.query.id;
      if (this.id) {
        let res = await get("/index/article/findById", { id: this.id });
        console.log(res, "res");
        this.categoryName = res.data.category.name;
        this.title = res.data.title;
        this.content = res.data.content;
      }
      console.log(this.id);
    },
    toDetailList(id) {
      this.$router.push({
        path: "/DetailList",
        query: { id },
      });
      this.$router.go(0)
    },
    // 分页跳转
    handleSizeChange(val) {
      // val选择每页展示的条数
      // 将每页要展示的数据的条数进行更新
      this.pageSize = val;
      // 将当前的页数 重置到第一页
      this.currentPage = 1;
      console.log("val", val);
    },
    // 监听当前页码变化
    handleCurrentChange(val) {
      // 将当前页数与分页插件动态点击控制页数相绑定
      this.currentPage = val;
      // 重新调用获取所有数据的方法
      this.getList();
    },
  },
  components: { Header, Footer },
};
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}
.content_detail,
.content_content {
  width: 1100px;
  height: 450px;
  font-family: 宋体;
  margin: 30px auto;
  display: flex;
}
.content_content {
  height: 100%;
}
.content_left {
  width: 250px;
  height: 100%;
  margin-right: 30px;
  div {
    height: 50px;
    line-height: 50px;
    background-color: #005825;
    color: white;
    text-align: center;
    font-weight: 800;
    font-size: 25px;
  }
}
.content_right_detail,
.content_right_content {
  width: 820px;
  position: relative;
}
// .content_right_content{
//   height: 1000px;
// }
.content_right_top {
  border-bottom: 3px solid #005825;
  margin-bottom: 5px;
  height: 50px;
  color: #005825;
  line-height: 50px;
  div {
    font-size: 16px;
    float: right;
    padding: 0 10px;
  }
  .content_right_title {
    font-size: 28px;
    float: left;
  }
}
.content_right_center {
  width: 820px;
  font-size: 17px;
  li {
    height: 40px;
    line-height: 40px;
    border-bottom: 1px dotted rgba(170, 165, 165, 0.76);
    padding: 0 10px;
  }
}
.content_right_bottom {
  text-align: center;
  position: absolute;
  bottom: 30px;
  right: 15%;
}
.content_content_title {
  line-height: 50px;
  font-size: 25px;
  font-weight: 800;
  text-align: center;
  color: black;
}
</style>
